package cn.iocoder.yudao.module.team.service.scenicspot;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.team.controller.admin.scenicspot.vo.*;
import cn.iocoder.yudao.module.team.dal.dataobject.scenicspot.ScenicspotDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.team.dal.mysql.scenicspot.ScenicspotMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.team.enums.ErrorCodeConstants.*;

/**
 * 景点资料 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ScenicspotServiceImpl implements ScenicspotService {

    @Resource
    private ScenicspotMapper scenicspotMapper;

    @Override
    public Integer createScenicspot(ScenicspotSaveReqVO createReqVO) {
        // 插入
        ScenicspotDO scenicspot = BeanUtils.toBean(createReqVO, ScenicspotDO.class);
        scenicspotMapper.insert(scenicspot);

        // 返回
        return scenicspot.getId();
    }

    @Override
    public void updateScenicspot(ScenicspotSaveReqVO updateReqVO) {
        // 校验存在
        validateScenicspotExists(updateReqVO.getId());
        // 更新
        ScenicspotDO updateObj = BeanUtils.toBean(updateReqVO, ScenicspotDO.class);
        scenicspotMapper.updateById(updateObj);
    }

    @Override
    public void deleteScenicspot(Integer id) {
        // 校验存在
        validateScenicspotExists(id);
        // 删除
        scenicspotMapper.deleteById(id);
    }

    @Override
        public void deleteScenicspotListByIds(List<Integer> ids) {
        // 删除
        scenicspotMapper.deleteByIds(ids);
        }


    private void validateScenicspotExists(Integer id) {
        if (scenicspotMapper.selectById(id) == null) {
            throw exception(SCENICSPOT_NOT_EXISTS);
        }
    }

    @Override
    public ScenicspotDO getScenicspot(Integer id) {
        return scenicspotMapper.selectById(id);
    }

    @Override
    public PageResult<ScenicspotDO> getScenicspotPage(ScenicspotPageReqVO pageReqVO) {
        return scenicspotMapper.selectPage(pageReqVO);
    }

    @Override
    public void updateCreateBatchScenicspot(List<ScenicspotDO> updateReqVO) {
        scenicspotMapper.insertOrUpdate(updateReqVO);
    }

}